package com.pdg.mcplugin.simpleconomy.dataproviders.bankmembers;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.pdg.mcplugin.common.interfaces.TableProviderValue;

public class BankMemberValue implements TableProviderValue<BankMemberValue>{
	public static final String FIELD_OWNER = "owner";
	private static final String CREATE_FIELDS = "`"+FIELD_OWNER+"` INT NOT NULL";
	private static final String INSERT_FIELDS = "`"+FIELD_OWNER+"`";
	private static final String INSERT_VALUES = "%d";
	private static final String SELECT_LIST = "`"+FIELD_OWNER+"`";
	private static final String UPDATE_LIST = "`"+FIELD_OWNER+"`=%d";
	private static final int TRUE_VALUE = 1;
	private static final int FALSE_VALUE = 0;
	private static final boolean DEFAULT_VALUE = false;
	
	private boolean owner;
	
	public BankMemberValue(boolean isOwner){
		setOwner(isOwner);
	}
	
	@Override
	public String getCreateFields() {
		return CREATE_FIELDS;
	}

	@Override
	public String getInsertFields() {
		return INSERT_FIELDS;
	}

	@Override
	public String getInsertValues() {
		return String.format(INSERT_VALUES,isOwner()?TRUE_VALUE:FALSE_VALUE);
	}

	@Override
	public String getSelectList() {
		return SELECT_LIST;
	}

	@Override
	public String getUpdateList() {
		return String.format(UPDATE_LIST,isOwner()?TRUE_VALUE:FALSE_VALUE);
	}

	@Override
	public BankMemberValue createValueFromResultSet(ResultSet theResultSet) {
		try {
			return new BankMemberValue(theResultSet.getInt(FIELD_OWNER)!=FALSE_VALUE);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	public static BankMemberValue defaultInstance(){
		return new BankMemberValue(DEFAULT_VALUE);
	}

	public boolean isOwner() {
		return owner;
	}

	public void setOwner(boolean owner) {
		this.owner = owner;
	}

}
